package web.controller;



import Commons.enums.Gender;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.InitBinder;
import web.binder.CustomGenderPropertyEditor;
import web.binder.PointFormatter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

@ControllerAdvice(basePackages = {"web.controller"})
public class ConmonController {
    @InitBinder
    public void initBinder(WebDataBinder dataBinder){
        DateFormat dataFormat=new SimpleDateFormat("yyyy/MM/dd");
        dataBinder.addCustomFormatter(new PointFormatter());
        dataBinder.registerCustomEditor(Date.class,new CustomDateEditor(dataFormat,true));
        dataBinder.registerCustomEditor(Gender.class,new CustomGenderPropertyEditor("男","女"));
    }

    @ExceptionHandler(RuntimeException.class)
    public String handleError(){
        return "welcome";
    }
}
